package drds.global_transaction.api.message_codec.request_and_response.transaction.branch_transaction.branch_transaction_end_status_report;

import java.nio.ByteBuffer;

import drds.global_transaction.api.api.BranchTransactionStatus;
import drds.global_transaction.api.message_codec.request_and_response.transaction.TransactionResponse;
import io.netty.buffer.ByteBuf;
import lombok.Getter;
import lombok.Setter;

public abstract class BranchTransactionEndStatusReportResponseMessage extends TransactionResponse
{
	private static final long serialVersionUID = 1L;
	@Setter
	@Getter
	protected BranchTransactionStatus branchTransactionStatus;

	@Override
	protected void doEncode()
	{
		super.doEncode();
		byteBuffer.put((byte) branchTransactionStatus.ordinal());
	}

	@Override
	public void decode(ByteBuffer byteBuffer)
	{
		super.decode(byteBuffer);
		branchTransactionStatus = BranchTransactionStatus.get(byteBuffer.get());
	}

	@Override
	public boolean decode(ByteBuf byteBuf)
	{
		boolean decode = super.decode(byteBuf);
		if (!decode)
		{
			return decode;
		}
		branchTransactionStatus = BranchTransactionStatus.get(byteBuf.readByte());
		return true;
	}
}
